package com.neusoft.yuejian_01.activity;

import android.content.Context;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.base.BaseActivity;
import com.neusoft.yuejian_01.javabean.TrainRegBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.model.TrainModel;

public class TrainRegActivity extends BaseActivity implements RetrofitListener{
    private TextView trainuserphoneView;
    private TextView trainpriceView;
    private TextView trainnameView;
    private TextView traintypeView;
    private TextView trainuserView;
    private ImageView trainpass;
    protected Context context;
    private ImageButton button_back;//返回按钮
    private int t_id;

     protected void initView() {
         setContentView(R.layout.activity_train_reg);
        trainuserphoneView = (TextView) findViewById(R.id.trainphone);
        trainpriceView = (TextView) findViewById(R.id.trainprice);
        trainnameView = (TextView) findViewById(R.id.trainname);
        trainuserView = (TextView) findViewById(R.id.trainusername);
        traintypeView = (TextView) findViewById(R.id.traintype);
        button_back = (ImageButton) findViewById(R.id.button_back);
        trainpass = (ImageView) findViewById(R.id.trainpass);
    }
     protected void initEvents() {
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
     protected void initData() {
        t_id = getIntent().getIntExtra("t_id",-1);
        TrainModel trainModel = new TrainModel();
        trainModel.trainreg(String.valueOf(getUser_id()),String.valueOf(t_id),this);
    }
    @Override
    public void onSuccess(Object object, int flag) {
        TrainRegBean trainRegBean = (TrainRegBean) object;
        trainuserphoneView.setText(trainRegBean.getU_phone());
        trainpriceView.setText(String.valueOf(trainRegBean.getT_price()));
        if (String.valueOf(trainRegBean.getT_type()).equals("0")){
            traintypeView.setText("入门");
        }
        if (String.valueOf(trainRegBean.getT_type()).equals("1")){
            traintypeView.setText("进阶");
        }
        if (String.valueOf(trainRegBean.getT_type()).equals("2")){
            traintypeView.setText("高级");
        }
        trainuserView.setText(trainRegBean.getU_name());
        trainnameView.setText(trainRegBean.getT_name());
        if (trainRegBean.getTn_pass().equals("1")){
            //已通过审核
            trainpass.setImageResource(R.drawable.ic_checkeds);
        }
        else {
            //未通过审核
            trainpass.setImageResource(R.drawable.ic_checks);
        }
    }
    @Override
    public void onFail() {
        Toast.makeText(this,"fail",Toast.LENGTH_LONG).show();
    }
}
